﻿ -- TGenres
DROP TABLE IF EXISTS TGenres;
DROP SEQUENCE IF EXISTS SQGenres;

 -- TGenres.genre_id sequence
CREATE SEQUENCE SQGenres;
GRANT ALL ON SEQUENCE SQGenres TO "watchMoviesModifiers";

CREATE TABLE TGenres (
genre_id 		INTEGER 		PRIMARY KEY DEFAULT NEXTVAL('SQGenres'),
genre_name		TEXT
);
GRANT ALL ON TABLE TGenres TO "watchMoviesModifiers";

CREATE OR REPLACE FUNCTION F_TGenres_Add_Genre(TEXT) RETURNS VOID AS
	$$ 
		INSERT INTO TGenres (genre_name) SELECT $1 WHERE NOT EXISTS ( SELECT genre_name from TGenres WHERE genre_name=$1 )
	$$ 
	LANGUAGE SQL;
GRANT ALL ON FUNCTION F_TGenres_Add_Genre(TEXT) TO "watchMoviesModifiers";